package com.example.demo.interceptor

import android.content.Context
import android.util.Log
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import java.util.logging.Logger

/**
 * @author yaotianxue
 * @description 路由拦截器（面向切面）
 * @date 2025/1/8
 */
@Interceptor(priority = 8 , name = "test1")
class TestInterceptor:IInterceptor {
    override fun init(context: Context?) {
        Log.d("IInterceptor", "init: ")
    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
       //做判断
        if (postcard?.path == "/home/HomeActivity"){
            Log.d("IInterceptor", "放行: ")
            callback?.onContinue(postcard) //放行
        }else{
            Log.d("IInterceptor", "拦截: ")
            callback?.onInterrupt(null) //拦截
        }
    }
}